﻿using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace Batik.Web.UI
{
    public class BasePage : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (System.Web.UI.ScriptManager.GetCurrent(this.Page) == null)
            {
                ScriptManager batikScriptManager = new ScriptManager();
                batikScriptManager.ID = "batikScriptManager";
                batikScriptManager.EnablePartialRendering = true;

                ScriptReference MicrosoftAjax = new ScriptReference("~/Scripts/MicrosoftAjax/MicrosoftAjax.js");
                MicrosoftAjax.Path = "~/Scripts/MicrosoftAjax/MicrosoftAjax.js";
                MicrosoftAjax.Name = "MicrosoftAjax.js";
                batikScriptManager.Scripts.Add(MicrosoftAjax);

                ScriptReference MicrosoftAjaxTemplates = new ScriptReference();
                MicrosoftAjaxTemplates.Path = "~/Scripts/MicrosoftAjax/MicrosoftAjaxTemplates.js";
                MicrosoftAjaxTemplates.ScriptMode = ScriptMode.Debug;
                batikScriptManager.Scripts.Add(MicrosoftAjaxTemplates);

                ScriptReference jquery = new ScriptReference();
                jquery.Path = "~/Scripts/jQuery/jquery-1.3.2.js";
                jquery.ScriptMode = ScriptMode.Debug;
                batikScriptManager.Scripts.Add(jquery);

                foreach (Control c in this.Controls)
                {
                    if (c is HtmlForm)
                    {
                        c.Controls.AddAt(0, batikScriptManager);
                        break;
                    }
                }
            }
        }
    }
}
